package com.cs171.market.service;

import com.auth0.jwt.JWT;
import com.auth0.jwt.algorithms.Algorithm;
import com.cs171.market.entity.User;
import org.springframework.stereotype.Service;

/**
 * @author Endy
 * @create 2020 - 05 - 22 - 11:12
 * @date 2020/5/22 - 11:12
 */

@Service("TokenService")
public class TokenService {
    public String getToken(User user){
        String token = "";
        //吧username保存在token中，并且把password作为密钥
        token = JWT.create().withAudience(user.getUname())
                .sign(Algorithm.HMAC256(user.getUpassword()));
        return token;
    }

}
